Skip to content

fix: replace crypto.randomUUID with compatible helper for HTTP contexts#29

Open
yuhp wants to merge 2 commits intoibelick:mainfrom
yuhp:fix/random-uuid-compatibility
Open

fix: replace crypto.randomUUID with compatible helper for HTTP contexts#29
yuhp wants to merge 2 commits intoibelick:mainfrom
yuhp:fix/random-uuid-compatibility

Conversation

@yuhp
Copy link

@yuhp yuhp commented Feb 14, 2026

Description

This PR fixes a crash when accessing the application over a local network (LAN) via HTTP (e.g., http://192.168.1.x:3000).

The Issue

The native crypto.randomUUID() method is restricted to Secure Contexts (HTTPS or localhost). When running the app in a development environment or self-hosted setup accessed via a local IP address, the browser disables this API, resulting in the following error:

Uncaught TypeError: crypto.randomUUID is not a function
    at createOptimisticMessage (chat-screen-utils.ts:14:27)
    ...

The Fix

I added a randomUUID helper function in src/lib/utils.ts that:

  1. Checks if window.crypto.randomUUID is available.
  2. Falls back to a math-based UUID v4 generator if running in an insecure context.
    I then replaced all direct usages of crypto.randomUUID() with this new helper in:
  • apps/webclaw/src/screens/chat/chat-screen.tsx
  • apps/webclaw/src/screens/chat/chat-screen-utils.ts
  • apps/webclaw/src/components/attachment-button.tsx

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How to Test

  1. Start the dev server (pnpm dev).
  2. Access the application using your machine's local LAN IP (e.g., http://192.168.x.x:3000) instead of localhost.
  3. Try to make a new session or chat with an existing session.
    Before fix:
  • The frontend page cannot make a new session or chat with old sessions.
  • The console logs the error: crypto.randomUUID is not a function.
    After fix:
  • New sessions function correctly.
  • Chatting within existing sessions works as expected.

return window.crypto.randomUUID()
}

// Fallback for insecure contexts (e.g. HTTP on LAN)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we switch the fallback to use crypto.getRandomValues instead of Math.random?

samgibson-bot pushed a commit to samgibson-bot/gold-dashboard that referenced this pull request Feb 18, 2026
…r LAN/HTTP contexts

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
samgibson-bot added a commit to samgibson-bot/gold-dashboard that referenced this pull request Feb 18, 2026
…belick#27, ibelick#14, #4, ibelick#29

* feat: PR ibelick#32 — device auth for OpenClaw v2026.2.14+ compatibility

- Add Ed25519 keypair generation, persistence (.device-keys.json, 0o600)
- Sign connect payload (v1|deviceId|clientId|...) via loadOrCreateDeviceIdentity
- Include device field in ConnectParams for all connection paths
- Handle WS close code 1008 with actionable log + device ID
- Graceful fallback if auth fails: connect proceeds without device field
- Preserve: 30s timeout, getGatewayScopes(), connection reuse cache
- Add PR ibelick#26 streaming infrastructure: gatewayRpcShared, acquireGatewayClient,
  gatewayEventStream, createGatewayClient
- Exclude .device-keys.json from git

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: PR ibelick#15 — slim Shiki bundle via createHighlighterCore

Replace createHighlighter with createHighlighterCore + JS regex engine.
Pre-load 29 explicit languages at init instead of dynamic loadLanguage().
Replace bundledLanguages import with SUPPORTED_LANGUAGES Set in utils.ts.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: PR ibelick#26 — /api/stream SSE endpoint with sanitizeError in catch

Add Server-Sent Events stream route using acquireGatewayClient.
All error paths use sanitizeError(). Heartbeat every 15s.
Update routeTree.gen.ts with full ApiStreamRoute registration.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: PR ibelick#27 — streamdown replaces react-markdown

Remove react-markdown, marked, remark-gfm, remark-breaks.
Rewrite markdown.tsx using Streamdown component.
PRESERVED: javascript: protocol blocking in a component (safeHref logic).
Add ThinkingLevel type and thinkingLevel setting to ChatSettings.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: PR ibelick#14 — pin sessions with localStorage persistence

Add usePinnedSessionsStore (Zustand + persist) in use-pinned-sessions.ts.
Update SessionItem with isPinned prop + onTogglePin callback + PinIcon button.
Update SidebarSessions to split pinned/unpinned with divider separator.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: PR #4 — image attachments with canvas compression and 5MB limit

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* feat: PR ibelick#29 — randomUUID utility with Math.random fallback for LAN/HTTP contexts

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix: PR ibelick#15 — use bundledThemes/bundledLanguages from shiki instead of @shikijs/* subpaths

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* chore: update routeTree.gen.ts after build (route order normalized)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Nathen McVittie <nathenmcvittie@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments